package com.edu.exam.enums.system;

import com.edu.exam.enums.core.BaseEnum;

/**
 * 文件类型枚举
 * 统一管理各类文件类型定义
 *
 * @author System
 * @version 1.0.0
 */
public enum FileType implements BaseEnum {

    // === 文档类型 ===
    PDF("PDF", "PDF文档"),
    DOC("DOC", "Word文档"),
    DOCX("DOCX", "Word文档"),
    TXT("TXT", "文本文件"),
    RTF("RTF", "RTF文档"),

    // === 表格类型 ===
    XLS("XLS", "Excel表格"),
    XLSX("XLSX", "Excel表格"),
    CSV("CSV", "CSV文件"),

    // === 演示文稿类型 ===
    PPT("PPT", "PowerPoint演示"),
    PPTX("PPTX", "PowerPoint演示"),

    // === 图片类型 ===
    JPG("JPG", "JPEG图片"),
    JPEG("JPEG", "JPEG图片"),
    PNG("PNG", "PNG图片"),
    GIF("GIF", "GIF图片"),
    BMP("BMP", "BMP图片"),
    SVG("SVG", "SVG图片"),
    TIFF("TIFF", "TIFF图片"),

    // === 音频类型 ===
    MP3("MP3", "MP3音频"),
    WAV("WAV", "WAV音频"),
    AAC("AAC", "AAC音频"),
    FLAC("FLAC", "FLAC音频"),

    // === 视频类型 ===
    MP4("MP4", "MP4视频"),
    AVI("AVI", "AVI视频"),
    MOV("MOV", "MOV视频"),
    WMV("WMV", "WMV视频"),
    FLV("FLV", "FLV视频"),

    // === 压缩文件类型 ===
    ZIP("ZIP", "ZIP压缩包"),
    RAR("RAR", "RAR压缩包"),
    TAR("TAR", "TAR压缩包"),
    GZ("GZ", "GZ压缩包"),
    _7Z("7Z", "7Z压缩包"),

    // === 代码文件类型 ===
    JAVA("JAVA", "Java源码"),
    JS("JS", "JavaScript源码"),
    CSS("CSS", "CSS样式"),
    HTML("HTML", "HTML文件"),
    XML("XML", "XML文件"),
    JSON("JSON", "JSON文件"),

    // === 其他类型 ===
    EXE("EXE", "可执行文件"),
    MSI("MSI", "安装包"),
    APK("APK", "Android应用"),
    OTHER("OTHER", "其他文件");

    private final String code;
    private final String description;

    FileType(String code, String description) {
        this.code = code;
        this.description = description;
    }

    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getDescription() {
        return description;
    }

    /**
     * 根据编码查找枚举值
     *
     * @param code 业务编码
     * @return 对应的枚举值
     */
    public static FileType fromCode(String code) {
        for (FileType value : values()) {
            if (value.getCode().equals(code)) {
                return value;
            }
        }
        throw new IllegalArgumentException("Unknown file type code: " + code);
    }
    /**
     * 根据描述查找枚举值
     *
     * @param description 显示描述
     * @return 对应的枚举值
     */
    public static FileType fromDescription(String description) {
        for (FileType value : values()) {
            if (value.getDescription().equals(description)) {
                return value;
            }
        }
        throw new IllegalArgumentException("Unknown file type description: " + description);
    }

    @Override
    public String toString() {
        return description;
    }
}